package net.lanelife.casino.cms.web.controller;

import java.util.List;

import javax.servlet.ServletRequest;

import net.lanelife.casino.caipiao.dto.admin.DigitalSelectorCreateDTO;
import net.lanelife.casino.caipiao.dto.admin.DigitalSelectorDTO;
import net.lanelife.casino.caipiao.dto.admin.DigitalSelectorTable;
import net.lanelife.casino.caipiao.dto.admin.DigitalSelectorUpdateDTO;
import net.lanelife.casino.caipiao.dto.admin.PlayMethodRuleCreateDTO;
import net.lanelife.casino.caipiao.dto.admin.PlayMethodRuleDTO;
import net.lanelife.casino.caipiao.dto.admin.PlayMethodRuleTable;
import net.lanelife.casino.caipiao.dto.admin.PlayMethodRuleUpdateDTO;
import net.lanelife.casino.caipiao.entity.DigitalSelector;
import net.lanelife.casino.caipiao.entity.PlayMethodRule;
import net.lanelife.casino.caipiao.service.api.IDigitalSelectorService;
import net.lanelife.casino.caipiao.service.api.IPlayMethodRuleService;
import net.lanelife.casino.cms.web.controller.support.CRUDController;
import net.lanelife.casino.common.repository.SearchFilter;
import net.lanelife.casino.common.service.support.IGenericService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping(value = DigitalSelectorController.PATH)
public class DigitalSelectorController extends CRUDController<DigitalSelector, Integer, DigitalSelectorDTO, DigitalSelectorCreateDTO, DigitalSelectorUpdateDTO, DigitalSelectorTable<DigitalSelectorDTO>> {
	
	public static final String PATH = "/digital-selector";
	
	public DigitalSelectorController() {
		super(PATH);
	}

	@Autowired
	private IDigitalSelectorService digitalSelectorService;
	
	@Autowired
	private IPlayMethodRuleService playMethodRuleService;
	
	@Override
	protected IGenericService<DigitalSelector, Integer> getService() {
		return digitalSelectorService;
	}
	
	@Override
	protected void preList(Model model, ServletRequest request) throws Exception {
		model.addAttribute("rule", playMethodRuleService.find(Integer.valueOf(request.getParameter("ruleId"))));
	}

	@Override
	protected void postList(Model model, Pageable pageable, ServletRequest request, List<SearchFilter> filters) throws Exception {
		filters.add(new SearchFilter("ruleId", SearchFilter.Operator.EQ, Integer.valueOf(request.getParameter("ruleId"))));
	}

}
